<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>创建合同订单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
    <script src="${ctxStatic}/js/DateTimePicker.js"></script>
    <script src="${ctxStatic}/js/layer.js"></script>
    <script src="${ctxStatic}/js/style.js"></script>
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/css/common.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script type="text/javascript">
    $(document).ready(function(){
    	var form = $("#inputForm");  
        form.validate();//验证指定的表单
    	$("#ognizationID").select2();
    	$("#orderType").select2();
    	$("#orderStatus").select2();
    	$("#contractCurrency").select2();
    	$("#transportMode").select2();
    	$("#balanceMode").select2();
    	
   		$("#okButton").click(function(){
    		if (form.valid()) {//如果表单验证成功，则进行提交。  
    		$("#showHtml").addClass("showHtml");
            $("#okHead").show();
            $("#createHead").hide();  
            $("#advanceDueDate").removeClass("laydate-icon");
            $("#appDate").removeClass("laydate-icon");
            return false;
          	}
     	});
    });
    
    /* 保存创建/编辑信息 */
    function saveForm(){
    	unFormat($("#advanceAmount"));
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/purchase/advance/save",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		 window.parent.frames[0].searchListForm();
    		closeWin();
    	},'json');
    	
    }
    /* 计算联动 */
    function myMath(obj,num){
    	var contractAmount = $("#contractAmount").val().replace(",","");
    	var result;
    	if (num == 0) {
			var advanceAmount = $(obj).val();
			result = (parseFloat(advanceAmount)/parseFloat(contractAmount))*parseFloat(100);
			$("#advanceRate").val(result);
			formatMoney($("#advanceRate"), 2);
		}
		if (num == 1) {
			var advanceRate = $(obj).val();
			result = (parseFloat(advanceRate)/parseFloat(100))*parseFloat(contractAmount)
			$("#advanceAmount").val(result);
			formatMoney($("#advanceAmount"), 2);
		}
    	
    }
    function findMaterial(tId){
    	param = {"id":tId};
    	$.post("${ctx}/purchase/contract/findMaterial",param,function(result){
            var h = $(callBackHtml(result)).find("#parentTable").html();
            $('#parentTable').html(h);
    		
    	},'html');
    	
    }
    
    </script>
    <style type="text/css">
    .linkBox{
	color:#0a6dca;
	cursor:pointer;
	text-decoration:underline;
	}
	.showHtml input{
	border:none;
	background-color:inherit;
	color:#333;
	}
    </style>
</head>
<form id="inputForm">
<body>   

<div id="createHead" class="layerHeader clearfix">
<c:choose>
	   <c:when test="${purchaseAdvance.id!=null && purchaseAdvance.id!=''}">
	    <!-- 编辑 --> 
			<p class="headerTitle"><spring:message code="purchaseAdvance_edit_editContract"/></p>
       </c:when>
       <c:otherwise>
        <!-- 创建 --> 
            <p class="headerTitle"><spring:message code="purchaseAdvance_edit_createContract"/></p>
       </c:otherwise>
    </c:choose>
	
    <div class="headerButton clearfix">
        <!-- 确定 -->
        <button type="button" id="okButton"><spring:message code="purchaseAdvance_edit_ok"/></button>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>
<!-- 确认画面头部 -->
<div id="okHead" class="layerHeader clearfix" style="display: none;">	      
             <p class="headerTitle"><spring:message code="purchaseAdvance_edit_Ok" /></p>    
    <div class="headerButton clearfix">
    <c:choose>
	   <c:when test="${purchaseAdvance.id!=null && purchaseAdvance.id!=''}">
	    <!-- 编辑 保存 --> 
	    <shiro:hasPermission name="purchase:advance:edit">
			<button type="button" onclick="saveForm();"><spring:message code="common_save" /></button>
			</shiro:hasPermission>
       </c:when>
       <c:otherwise>
        <!-- 创建 保存 --> 
        <shiro:hasPermission name="purchase:advance:edit">
            <button type="button" onclick="saveForm();"><spring:message code="common_save" /></button>
            </shiro:hasPermission>
       </c:otherwise>
     </c:choose>
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>

<div id="showHtml" class="smOrderBox">
<div class=" clearfix" >
        	<p class="title" style="margin-top: 2px"><spring:message code="purchaseAdvance_edit_contractMessage"/></p>
        </div>
        <input type="hidden" id="id" name="id" value="${purchaseAdvance.id }">
	<input type="hidden" id="contractMaterialID" name="contractMaterialID" value="${purchaseAdvance.contractMaterialID }">
    <div class="items clearfix">
        <div class="col-33 clearfix haveToBox">
        <!-- 采购合同号 -->
            <p class="tit"><spring:message code="purchaseAdvance_edit_contractMaterialNO"/></p>
            <input type="text" id="contractMaterialNO" name="contractMaterialNO" value="${purchaseAdvance.contractMaterialNO }" readonly="readonly" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_contractMaterialNO"/>">
            <button type="button" onclick="popup('990px','584px','${ctx}/purchase/advance/contractList')"><spring:message code="purchaseAdvance_edit_select"/></button>
            <p class="haveTo">*</p>
        </div>
        <div class="col-33 clearfix showHtml">
        <!-- 供货商  -->
            <p class="tit"><spring:message code="purchaseAdvance_edit_ognizationName"/></p>
             <input type="text" id="ognizationName" value="${purchaseAdvance.ognizationName }" disabled="disabled">
        </div>
        
    </div>
    <div class="items clearfix">
        <div class="col-33 clearfix haveToBox">
        <!-- 申请日期  -->
            <p class="tit"><spring:message code="purchaseAdvance_edit_appDate"/></p>
            <input type="text" onblur="CheckDate(this);" 
								id="appDate" name="appDate"  value="<fmt:formatDate value="${purchaseAdvance.appDate }" pattern="yyyy-MM-dd" />" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_appDate"/>">
            <p class="haveTo">*</p>
        </div>
        <div class="col-33 clearfix showHtml">
        <!-- 开户银行  -->
            <p class="tit"><spring:message code="purchaseAdvance_edit_bankName"/></p>
             <input type="text" id="bankName" value="${purchaseAdvance.bankName }" disabled="disabled">
        </div>
        <div class="col-33 clearfix showHtml">
        <!-- 银行账户  -->
            <p class="tit"><spring:message code="purchaseAdvance_edit_bankAccountNo"/></p>
            <input type="text" id="bankAccountNo" value="${purchaseAdvance.bankAccountNo }" disabled="disabled">
        </div>
    </div>
    <div class="items clearfix" >        	
                <div class="col-33 clearfix haveToBox">
                <!-- 付款期限 -->
                    <p class="tit"><spring:message code="purchaseAdvance_edit_advanceDueDate"/></p>
                    <input type="text" onblur="CheckDate(this);" 
								id="advanceDueDate" name="advanceDueDate"  value="<fmt:formatDate value="${purchaseAdvance.advanceDueDate }" pattern="yyyy-MM-dd" />" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceDueDate"/>">&ensp;<spring:message code="purchaseAdvance_edit_before"/>
                    <p class="haveTo">*</p>
                </div>
                
                <div class="col-33 clearfix showHtml">
                <!-- 采购数量  -->
                    <p class="tit"><spring:message code="purchaseAdvance_edit_contractQuantity"/></p>
                    <input type="text" id="contractMaterialQuantity" value="${purchaseAdvance.contractMaterialQuantity }" disabled="disabled">
                </div>
                <div class="col-33 clearfix showHtml">
                <!-- 采购金额  -->
                    <p class="tit"><spring:message code="purchaseAdvance_edit_contractAmount"/></p>
                    <input type="text" id="contractAmount" value="${purchaseAdvance.contractAmount }" disabled="disabled">
                </div>
            </div>
    
            <div class="items clearfix haveToBox">        	
                <div class="col-33 clearfix">
                <!-- 预付款金额  -->
                    <p class="tit"><spring:message code="purchaseAdvance_edit_advanceAmount"/></p>
                    <input type="text" id="advanceAmount" name="advanceAmount" value="<fmt:formatNumber value="${purchaseAdvance.advanceAmount }"  pattern="#,##0.00#"/>" onfocus="unFormat(this);" onblur="formatMoney(this, 2);" onchange="myMath(this,0);" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceAmount"/>">
           			<p class="haveTo">*</p>
                </div>
                <div class="col-33 clearfix haveToBox">
                <!-- 预付款比例  -->
                    <p class="tit"><spring:message code="purchaseAdvance_edit_advanceRate"/></p>
                    <input type="text" id="advanceRate" name="advanceRate" value="<fmt:formatNumber value="${purchaseAdvance.advanceRate }"  pattern="###0.00#"/>" onchange="myMath(this,1);" style="width: 40px" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceRate"/>">
                    <span>&ensp;%</span>
                	<p class="haveTo">*</p>
                </div>
                <div class="col-33 clearfix showHtml">
                <!-- 创建人员  -->
            		<p class="tit"><spring:message code="purchaseAdvance_edit_creator"/></p>
            		<input type="text" id="" name="" value="${purchaseAdvance.createBy.firstName }${purchaseAdvance.createBy.lastName }" disabled="disabled">
        		</div>
            </div>
            <div class="items clearfix showHtml">
                
        		<div class="clearfix">
        		<!-- 申请原因 -->
            		<p class="tit"><spring:message code="purchaseAdvance_edit_advanceReason"/></p>
            		<textarea name="advanceReason" style="width:790px;height: 60px">${purchaseAdvance.advanceReason }</textarea>
        		</div>
           
    </div>
    <div class=" clearfix" >
        	<p class="title" style="margin-top: 2px"><spring:message code="purchaseAdvance_edit_contractBasicMessage"/></p>
        </div>
</div>

<div class="tableArea">
    <div class="tableScroll tableScrollSm" style="margin-left: 10px;">
        <table cellpadding="0" class="tableHead">
            <thead>
            <tr>
                        <th class="tab-wltp"><spring:message code="purchaseContract_edit_materailImage"/></th>
                        <th class="tab-wlmcbj"><spring:message code="purchaseContract_edit_materailNameNO"/></th>
                        <th class="tab-fk"><spring:message code="purchaseContract_edit_materailSpec"/></th>
                        <th class="tab-dw"><spring:message code="purchaseContract_edit_materailSpecUnit"/></th>
                        <th class="tab-hjje"><spring:message code="purchaseContract_edit_supplierName"/></th>
                        <th class="tab-zdj"><spring:message code="purchaseContract_edit_contractNO"/></th>
                        <th class="tab-zdj"><spring:message code="purchaseContract_edit_reserveQuantity"/></th>
                        <th class="tab-jj"><spring:message code="purchaseContract_edit_realityQuantity"/></th>
                        <th class="tab-jj"><spring:message code="purchaseContract_edit_unitPrice"/></th>
                        <th class="tab-jj"><spring:message code="purchaseContract_edit_quantity"/></th>
                        <th class="tab-jj"><spring:message code="purchaseContract_edit_otherCost"/></th>
                        <th class="tab-jj"><spring:message code="purchaseContract_edit_amount"/></th>
                
            </tr>
            </thead>
        </table>
        <table cellpadding="0" class="tableBody" id="parentTable">
            <tbody id="sListHtml">
            <c:forEach items="${purchaseContract.materialList }" var="material" varStatus="status">
            <tr class="table-TR">
                <td class="tab-wltp"><c:if test="${material.materialFile!=null && material.materialFile!='' }"><img src="${material.materialFile }" class="wltp"></c:if><c:if test="${material.materialFile==null||material.materialFile=='' }"><img src="${ctxStatic}/images/pic-none.jpg" class="wltp"></c:if></td>
                        <td class="tab-wlmcbj">${material.materialCode }<br>${material.materialNameCN }</td>
                        <td class="tab-fk">${material.materialSpec }</td>
                        <td class="tab-dw">${fns:getDictName(material.materialSpecUnitCD) }</td>
                        <td class="tab-hjje">${material.ognizationNameB }</td>
                        <td class="tab-zdj">${material.contractNO }</td>
                        <td class="tab-zdj">${material.reserveQuantity }</td>
                        <td class="tab-jj">${material.realityQuantity }</td>
                        <td class="tab-jj">${material.purchaseUnitPrice }</td>
                        <td class="tab-jj">${material.purchaseReserveQuantity }</td>
                        <td class="tab-jj">${material.purchaseOtherCost }</td>
                        <td class="tab-jj"><fmt:formatNumber value="${material.purchaseUnitPrice*material.purchaseReserveQuantity + material.purchaseOtherCost }" pattern="0.#####"/></td>
            </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</div>
</form>
<script>
	window.onload = function(){
	$('.tableScrollSm').css('height','280px')
	$('td input').each(function(){
		var tdH = $(this).parents('td').height()
		$(this).css('height',tdH)
		})
	}
	var tableW = $('.tableHead').outerWidth();
	$('.tableScroll').css('width',tableW + 18 + 'px')

</script>
</body>
</html>
